home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!inteleNET!usenet
- From: chalain@mcr.net (Chalain)
- Newsgroups: comp.lang.c++
- Subject: Question about header files
- Date: 5 Mar 1996 01:22:37 GMT
- Organization: inteleNET Internet Services
- Message-ID: <4hg50t$924@vodka.intele.net>
- NNTP-Posting-Host: 206.29.210.159
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- Anyone feeling generous? I have a question that wants an essay-style
- answer....
-
- First, the scene: I have Symantec C++ 6.1, nice compiler, no manuals.
- Got
- just the CD, which has manuals on it, but they are reference manuals and
- assume that I am fluent in C/C++ grammar. The problem is that I are not.
-
- A beginning C++ book I have says to do this (with Borland Turbo C++):
-
- In the main file (main.cpp), put the line
-
- #include "myheader.h";
-
- and in myheader.cpp, put the line
-
- #include "myheader.h";
-
- From this, I assume that the compiler, upon opening a *.h file, will
- check for a *.c or *.cpp file of the same name, yes?
-
- This confuses me just a little bit. However, it gets worse.
-
- I have a main C++ file called, appropriately enough, MAINFILE.CPP. It
- uses some homemade graphics functions that I have written myself. These
- are in a file called MYGRAPH.CPP, and their prototypes and structures
- are in a file called MYGRAPH.H. Now, here is where it gets fun.
-
- I assign a pointer to the mode 0x13 video memory with the line
-
- unsigned char far *video_buffer = (unsigned char far *)0xA0000000L;
-
- I would *really* like to put this line either in the header file or in
- the code file for graphics, but if I do I can't get access to the pointer
- in MAINFILE or any of its other dependents. Right now I'm defining it
- globally in MAINFILE. Crude, but effective. Is there a more elegant way
- to put this pointer in the graphics files yet still give it global scope?
- Be aware that I am using Symantec C++ and am compiling from the DOS
- prompt,
- so there aren't any IDE options or project resources that I can add or
- tinker with.
-
- Secondly, I have an extension of my set of graphics function to cope with
- PCX graphic files. These functions are in PCXFILE.H and PCXFILE.CPP.
- I would like to include these files as is, but right now the code just
- will not compile. I either get "identifier already defined" at compile
- time if I put #include MYGRAPH and #include PCXFILE in MAINFILE or
- "unknown
- identifier" at link time if I put #include PCXFILE inside MYGRAPH.H.
- Right
- now my work around is to case and paste the entire PCX function set into
- the
- MYGRAPH files... an inelegant and poorly portable solution if ever there
- was
- one!
-
- So here are my questions:
-
- Can my graphics file be written so that it is just "plugs in" without
- having to define global pointers in the main file? (Can I define
- identifiers there that will be used in the MAINFILE?)
-
- Can my PCXGRAPH file be written to "plug in" to the graphics file, such
- that it does not require its own set of graphics functions (and pointers,
- etc) yet MYGRAPH works with no modification with or without it? (Meaning
- that it will inherit access to MYGRAPH's functions, yet still pass
- functions, identifiers, and #defines up to MAINFILE?)
-
- Will Clint get out of the hospital in time to stop the wedding?
-
- Can someone explain to me how header files work in the "general case?"
- Ie., what happens when you #include a header file, what dependencies are
- checked, what gets compiled first, what happens if a header file
- #includes another header file, et cetera? I would be most grateful.
-
- Thank you very much in advance for any and all help given!
-
- Chalain
-
- P.S. For the sake of newbies like myself, feel free to reply to the
- newsgroup. For my sake, however, please reply via e-mail. My usenet
- priviledges are very limited.
-
-